package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import cqrtplm.service.OaApiService;
import cqrtplm.service.RTReviseObjectByEcnService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

import java.math.BigInteger;

/**
 * $ 方法的功能描述.
 *
 * @author Administrator$
 * @return $ 的说明
 * @date 2025/11/11$ 下午3:15$
 * @since 1.0
 */
@Slf4j
@CustomListener(category = "润通", description = "涉及在途影响订单下发OA会签")
public class RTSendOAOrderListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) {
        try {
            log.info("开始执行监听 ==> 涉及在途影响订单下发OA会签");
            String workFlowContainerId = execution.getProcessInstanceBusinessKey();
            if (StringUtils.isBlank(workFlowContainerId)) {
                workFlowContainerId = execution.getVariable("workFlowContainerId").toString();
            }
            OaApiService oaApiService = SpringUtil.getBean(OaApiService.class);
            oaApiService.sendOrderDataToOa(new BigInteger(workFlowContainerId));
            log.info("正常执行监听结束 <== 涉及在途影响订单下发OA会签END");
        } catch (Exception e) {
            log.error("监听RTReviseMbomsByEcnListener异常：", e);
            throw e;
        }
    }
}
